import requests
from jsonpath import jsonpath
import json

def get_data(url, h):

    r = requests.get(url, headers=h)
    if r.status_code == 200:
        # print(r.text)
        data_r = r.text
        return data_r

def jiexi_data(data_r):


    data_new = data_r.split("data_callback(")[1]
    data_news = data_new.split(")")[0]
    data_json = json.loads(data_news)
    title = jsonpath(data_json,"$..title")
    for i in title:
        print(i)

if __name__ == '__main__':
    url = 'https://news.163.com/special/cm_yaowen20200213/?callback=data_callback'
    h = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36',
        'Referer': 'https://news.163.com/',
    }

    data_r = get_data(url, h)
    jiexi_data(data_r)























